class Solution
{
public:
    int sumFourDivisors(vector<int> &nums)
    {
        int result = 0;
        for (int num : nums)
        {
            int count = 0, factorSum = 0;
            for (int i = 1; i * i <= num; ++i)
            {
                if (num % i == 0)
                {
                    ++count;
                    factorSum += i;
                    if (i * i != num)
                    {
                        ++count;
                        factorSum += num / i;
                    }
                }
            }
            if (count == 4)
            {
                result += factorSum;
            }
        }
        return result;
    }
};
